package com.aphrodite.ui.graphics;

import com.aphrodite.image.ColorUtil;

/**
 * Represents a Gradient.
 * 
 * @author kentelt
 * 
 */
public final class Gradient {
	/**
	 * Represents a centered vertical or horizontal gradient rectangle.
	 * <p>
	 * Can be combined with {@link Gradient#TYPE_HORIZONTAL} or
	 * {@link Gradient#TYPE_VERTICAL}
	 * </p>
	 */
	public static final byte TYPE_CENTERED = 64;
	/**
	 * A Horizontal Gradient.
	 */
	public static final byte TYPE_HORIZONTAL = 4;
	/**
	 * Radial gradient
	 */
	public static final byte TYPE_RADIAL = 8;
	/**
	 * Rainbow colored gradient
	 * <p>
	 * This type does not need a start color and end color.
	 * </p>
	 */
	public static final byte TYPE_RAINBOW = 16;
	/**
	 * Represents a split of the specified colors.
	 * <p>
	 * Can be combinded with {@link Gradient#TYPE_HORIZONTAL} or
	 * {@link Gradient#TYPE_VERTICAL}
	 * </p>
	 */
	public static final byte TYPE_SPLIT = 32;
	/**
	 * A Vertical Gradient.
	 */
	public static final byte TYPE_VERTICAL = 2;

	private int endColor;
	private int startColor;
	private byte type;

	public Gradient() {
		this(TYPE_HORIZONTAL);
	}

	/**
	 * Creates a Gradient instance with default start and end colors
	 * <p>
	 * The start color used is Black. And the end color is White
	 * </p>
	 * 
	 * @see Gradient#setStartColor(int)
	 * @see Gradient#setEndColor(int)
	 * @param type
	 *            see {@link Gradient#TYPE_HORIZONTAL},
	 *            {@link Gradient#TYPE_VERTICAL}, {@link Gradient#TYPE_RADIAL},
	 *            {@link Gradient#TYPE_RAINBOW}, {@link Gradient#TYPE_SPLIT}.
	 * 
	 */
	public Gradient(byte type) {
		this(0, 0xffffff, type);
	}

	public Gradient(int startColor, int endColor, byte type) {
		this.startColor = startColor;
		this.endColor = endColor;
		this.type = type;
	}

	public final int getEndColor() {
		return endColor;
	}

	public final int[] getGradient(int steps) {
		return ColorUtil.getGradient(startColor, endColor, steps);
	}

	public final int getStartColor() {
		return startColor;
	}

	public final byte getType() {
		return type;
	}

	public final void setEndColor(int color) {
		this.endColor = color;
	}

	public final void setStartColor(int color) {
		this.startColor = color;
	}

	public final void setType(final byte type) {
		this.type = type;
	}
}
